<?php

namespace App\Http\Controllers\Auth;

use App\Models\Permission;
use App\Models\Role;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class PermissionsController extends Controller
{
    public function index()
    {
        $permissions = Permission::all();
        dd($permissions);
    }

    public function store()
    {

    }

    public function show()
    {
        
    }

    public function create()
    {
//        $createPost = new Permission();
//        $createPost->name = 'admin-index';
//        $createPost->display_name = '后台首页';
//        $createPost->description = 'create new blog posts';
//        $createPost->save();

//        $editUser = new Permission();
//        $editUser->name = 'edit-user';
//        $editUser->display_name = 'Edit Users';
//        $editUser->description = 'edit existing users';
//        $editUser->save();
        $createPost = Permission::where('name','admin-index')->first();

        $admin = Role::where('name','admin')->first();
        $admin->attachPermission($createPost);
        //等价于 $admin->perms()->sync(array($createPost->id));

        $owner = Role::where('name','owner')->first();
        $owner->attachPermission($createPost);
        //等价于 $owner->perms()->sync(array($createPost->id, $editUser->id));
    }

    public function destroy()
    {

    }

    public function update()
    {

    }

    public function edit()
    {

    }
}
